package LeetCode;

public class LC_482_LicenseKeyFormatting {

    public static void main(String[] args) {

    }

    class Solution {
        public String licenseKeyFormatting(String S, int K) {
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = S.length() - 1; i >= 0; i--)
                if (S.charAt(i) != '-') {
                    if (stringBuilder.length() % (K + 1) == K)
                        stringBuilder.append('-');
                    stringBuilder.append(S.charAt(i));
                }
            return stringBuilder.reverse().toString().toUpperCase();
        }

    }
}